From: Andrew Garrett Date: Mon, 30 Jul 2012 21:16:56 +0000 (-0700) Subject: Clean up badger.{css,js} from PageTriage, generalise it and move it into core. X-Git-Tag: 1.31.0-rc.0~22913 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=f239fb3905e6b3ade16b1c99c7bc4faca91ccdee;p=lhc%2Fweb%2Fwiklou.git Clean up badger.{css,js} from PageTriage, generalise it and move it into core. Change-Id: I0f5e754146359448eb125456e240cf5768d4f541 --- diff --git a/resources/Resources.php b/resources/Resources.php index 7b03171c49..337367f706 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -106,6 +106,10 @@ return array( 'scripts' => 'resources/jquery/jquery.autoEllipsis.js', 'dependencies' => 'jquery.highlightText', ), + 'jquery.badge' => array( + 'scripts' => 'resources/jquery/jquery.badge.js', + 'styles' => 'resources/jquery/jquery.badge.css', + ), 'jquery.byteLength' => array( 'scripts' => 'resources/jquery/jquery.byteLength.js', ), diff --git a/resources/jquery/jquery.badge.css b/resources/jquery/jquery.badge.css new file mode 100644 index 0000000000..f7eb692a02 --- /dev/null +++ b/resources/jquery/jquery.badge.css @@ -0,0 +1,38 @@ +.mw-badge { + min-width: 8px; + height: 14px; + border: 1px solid white; + border-radius: 8px; + -moz-border-radius: 8px; + -webkit-border-radius: 8px; + box-shadow: 0px 1px 4px #ccc; + -moz-box-shadow: 0px 1px 4px #ccc; + -webkit-box-shadow: 0px 1px 4px #ccc; + background-color: #b60a00; + background-image: linear-gradient(bottom, #a70802 0%, #cf0e00 100%); + background-image: -o-linear-gradient(bottom, #a70802 0%, #cf0e00 100%); + background-image: -moz-linear-gradient(bottom, #a70802 0%, #cf0e00 100%); + background-image: -webkit-linear-gradient(bottom, #a70802 0%, #cf0e00 100%); + background-image: -ms-linear-gradient(bottom, #a70802 0%, #cf0e00 100%); + background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #a70802), color-stop(1, #cf0e00)); + padding: 0 3px; + text-align: center; +} + +.mw-badge-content { + font-size: 12px; + line-height: 14px; + color: white; + vertical-align: top; +} + +.mw-badge-inline { + display: inline; +} + +.mw-badge-overlay { + position: absolute; + bottom: -1px; + right: -3px; + z-index: 50; +} \ No newline at end of file diff --git a/resources/jquery/jquery.badge.js b/resources/jquery/jquery.badge.js new file mode 100644 index 0000000000..d40acc6efc --- /dev/null +++ b/resources/jquery/jquery.badge.js @@ -0,0 +1,78 @@ +// Badger v1.0 by Daniel Raftery +// http://thrivingkings.com/badger +// http://twitter.com/ThrivingKings +// Modified by Ryan Kaldari + +/** + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * This program is distributed WITHOUT ANY WARRANTY. + */ + +(function( $ ) { + $.fn.badge = function( badge, options ) { + var existingBadge = this.find( '.mw-badge' ); + options = $.extend( {}, options ); + + badge = String(badge); + if ( badge.charAt(0) === '+' ) { + if ( existingBadge.length > 0 ) { + oldBadge = existingBadge.text(); + badge = Math.round( Number( oldBadge ) + Number( badge.substr(1) ) ); + } else { + badge = badge.substr(1); + } + } else if ( badge.charAt(0) === '-' ) { + if ( existingBadge.length > 0 ) { + oldBadge = existingBadge.text(); + badge = Math.round( Number( oldBadge ) - Number( badge.substr(1) ) ); + } else { + badge = 0; + } + } + + if ( Number(badge) <= 0 ) { + // Clear any existing badge + existingBadge.remove(); + } else { + // Don't add duplicates + var $badge = existingBadge; + if ( existingBadge.length > 0 ) { + this.find( '.mw-badge-content' ).text( badge ); + } else { + $badge = $('
') + .addClass('mw-badge') + .addClass('mw-badge-overlay') + .append( + $('') + .addClass('mw-badge-content') + .text(badge) + ); + this.append($badge); + } + + if ( options.type ) { + if ( options.type == 'inline' ) { + $badge.removeClass('mw-badge-overlay') + .addClass('mw-badge-inline'); + } else if ( options.type == 'overlay' ) { + $badge.removeClass('mw-badge-inline') + .addClass('mw-badge-overlay'); + } + } + + // If a callback was specified, call it with the badge number + if ( options.callback ) { + options.callback( badge ); + } + } + }; +} ) ( jQuery );